<%@ page import="swe.article.*"%>
<%@ page import="swe.user.*"%>
<%@ page import="java.util.List"%>

<jsp:include page="layout/header.jsp" />

<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.js' type="text/javascript"></script>
<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.MetaData.js' type="text/javascript" language="javascript"></script>
<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.js' type="text/javascript" language="javascript"></script>
<link href='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.css' type="text/css" rel="stylesheet"/>


<% if( (Boolean) session.getAttribute("isLoggedIn") == null) { 
	
	RequestDispatcher view = request.getRequestDispatcher("login.jsp");
	view.forward(request, response);
	
 }
 

 
 %>
 
 <% User user = (User) request.getSession(true).getAttribute("User"); %>



<div class="row">
	<div class="span12">
<h2>Ersteigerte/Gekaufte Artikel</h2>
		<table class="table table-striped">
			<thead>
				<tr>
					<th>Bezeichnung</th>
					<th>Ersteigert am</th>
					<th>Typ</th>
					<th>Preis</th>
					<th>abgegebene Bewertung</th>
				</tr>
			</thead>
			<tbody>
			<% 
        	if(request.getAttribute("articleList") != null) {
	        	List<Article> a = (List<Article>) request.getAttribute("articleList");
	        	for(int i = a.size(); i > 0; i--)   {	
	        		// Wenn user integriert, loeschen
         			if(a.get(i-1).getBids().size() == 0) {
         				continue;
         			}
      		%>
				<tr>
					<td><a href="Article?action=view&id=<%= a.get(i-1).getID() %>"><%= a.get(i-1).getTitle() %></a></td>
					<td><%= a.get(i-1).getLastBid().getCreatedHuman() %></td>
					<td><% if(a.get(i-1).getIsAuction()) {  %> Auktion / <%= a.get(i-1).getBids().size() %> Gebote<% } else { %> Sofort-Kauf<% } %></td>
					<td><%= a.get(i-1).getLastBid().getBidValue() %> &euro;</td>
					<td>
					<!-- RATING NEW START -->
					<% if (a.get(i-1).isRated()) {%>
					
						<div>
						
						<%= a.get(i-1).getRating().getRating() %>
						</div>
						<!--  ARTIKEL WURDE BEWERTET  -->
					<% } else { %>
						<!-- ARTIKEL WURDE NICHT BEWERTET -->
						
						<div>
					
						<form method="post" action="Article?action=addRating">
		 				<input type="hidden" name="userID" value="<%= user.getiD() %>" />
						<input type="hidden" name="articleID" value="<%= a.get(i-1).getID() %>" />
						
						<input name="star" id="star1" type="radio" class="star" value="1"/>
						<input name="star" id="star1" type="radio" class="star" value="2"/>
						<input name="star" id="star1" type="radio" class="star" value="3"/>
						<input name="star" id="star1" type="radio" class="star" value="4"/>
						<input name="star" id="star1" type="radio" class="star" value="5"/><br>
						<input type="submit" class="btn btn-primary" value="bewerten"/>
						</form>
						</div>
						
					<% } %>

					<!-- RATING NEW END -->
					</td>
				</tr>

			<% 
				}
        	} 
        	%>
			</tbody>
		</table>
	</div>
</div>


		<% if(request.getAttribute("errorMessage")!=null && !request.getAttribute("errorMessage").equals("")) { %>
				<div class="alert alert-error"><strong>Achtung!</strong> <%= request.getAttribute("errorMessage") %></div>
			<%}%>
			
			

<jsp:include page="layout/footer.jsp" />
